import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './index.css'

export default class index extends Component {

  static propTypes = {
    users:PropTypes.array.isRequired
  }

  toUserDetail = (url)=>{
    return ()=>{
      // window.location.href=url // 切换新的路由 在当前的窗口打开
      // window.open(url) // 打开新窗口 再进入指定的url
    }
  }

  render() {

    const {users,status} = this.props

    return (
      <div className="lists">
        {
          status === 0?'Enter keywords, then click search':
          status === 1?'Loadding...':
          status === 2?'搜索错误':
          users.map(user=>{
            return (
              <div onClick={this.toUserDetail(user.html_url)} key={user.id} className="items">
                <img src={user.avatar_url}  alt="avater"/>
                <span>{user.login}</span>
              </div>
            )
          })
        }
      </div>
    )
  }
}
